package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    public void work(BookList bookList) {
        System.out.println("借阅书籍");
        System.out.println("请输入想要借阅的书籍");
        Scanner in = new Scanner(System.in);
        String name = in.nextLine();
        for (int i = 0; i < bookList.getBookSize(); i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName()) && !(book.isBorrowde())) {
                book.setBorrowde(true);
                System.out.println("借阅成功");
            }else if (name.equals(book.getName()) && (book.isBorrowde())) {
                System.out.println("已被借走");
            }else {
                return;
            }
        }
    }
}
